import { useStore } from 'vuex'

export const useCommonCartEffect = () => {
  const store = useStore()
  const cartList = store.state.cartList
  const changeCartItem = (shopId, shopName, productId, productInfo, number) => {
    store.commit('changeCartItem', {
      shopId,
      shopName,
      productId,
      productInfo,
      number
    })
  }
  const changeCartItemState = (shopId, productId, checked) => {
    store.commit('changeCartItemState', {
      shopId,
      productId,
      checked
    })
  }
  const changeCartState = (shopId) => {
    store.commit('changeCartState', {
      shopId
    })
  }
  const clearCart = (shopId) => {
    store.commit('clearCart', {
      shopId
    })
  }
  return {
    changeCartItem,
    cartList,
    changeCartItemState,
    changeCartState,
    clearCart
  }
}
